﻿using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using SpreadsheetGear;
using System;

namespace WorkbookDesigner.Addons.DefineName
{
    public enum OperationType
    {
        Workbook, Worksheet
    }

    public static class Helper
    {
        /// <summary>
        /// 验证名称在指定的INames中是否存在，若存在则弹出是否替换的提示。未找到或确定替换返回true，已存在且不替换则返回false。
        /// </summary>
        /// <param name="names">指定的Names</param>
        /// <param name="name">将验证的名称文本</param>
        /// <returns></returns>
        public static bool ValidateName(INames names, string name)
        {
            if (string.IsNullOrEmpty(name))
                return false;
            
            bool notFound = names.Cast<IName>().All(ename => !string.Equals(ename.Name, name, StringComparison.CurrentCultureIgnoreCase));
            if (notFound)
                return true;
            switch (DesignerHelper.Help.MesBox.QuestionMessage($"是否替换现有名称{'"'}{name}{'"'}的定义？"))
            {
                case DialogResult.Yes:
                    return true;
                case DialogResult.No:
                    return false;
                default:
                    return false;
            }

        }
    }

}
